<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">员工姓名</label>
        <div class="layui-input-block">
            <input type="text" name="workerName" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="NMMhu" class="layui-input">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>
        
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="workerGender" value="男" title="男" checked="">
            <input type="radio" name="workerGender" value="女" title="女">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">手机</label>
        <div class="layui-input-block">
            <input type="text" maxlength="11" name="workerPhone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="13713896619" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">年龄</label>
        <div class="layui-input-block">
            <input type="text" maxlength="11" name="workerAge" lay-verify="required" lay-reqtext="年龄不能为空" placeholder="请输入年龄" value="18" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">身份证号</label>
        <div class="layui-input-block">
            <input type="text" maxlength="18" name="workerCode" placeholder="请输入身份证号" value="360725200501125515" class="layui-input">
        </div>
    </div>

    
    <div class="layui-form-item">
        <label class="layui-form-label" required="">职业</label>
        <div class="layui-input-block">
            <select id="Wobj" name="workerJob" lay-verify="">
                <option value="">--选择职位--</option>
                <option value="职务">职务</option>
                <option value="经理">经理</option>
              </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
            
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data.field);

            var formData = {  
            workerName:data.field.workerName, // 从表单元素中获取值  
            workerGender:data.field.workerGender,  
            workerAge:data.field.workerAge,
            workerCode:data.field.workerCode,
            workerPhone:data.field.workerPhone,
            workerJob:data.field.workerJob   
            };
            $.ajax({
                type:"post",
                url:"http://localhost:8080/restaurant_web_war_exploded/workers/insertWorkers",
                data:JSON.stringify(formData),
                contentType:'application/json',
                success:function (res){
                    var index= layui.layer.load(3, {  
                    shade: [1,'#fff']  })//0.1透明度的白色背景 
                    console.log(res);
                    if(res.errorCode==200){
                        var indexifr = parent.layer.getFrameIndex(window.name); // 获取当前 iframe 层的索引        
                        setTimeout(function(){
                        parent.layer.close(indexifr);
                        window.parent.postMessage('success', 'http://127.0.0.1:5500/index.html#/../html/workerInfo.html'); // '*' 表示目标源，慎用，建议使用具体的源      
                        },1000)

                        setTimeout(function(){   
                        layer.close(index);      
                        // 更新元素          
                        },1200);    
                    }
                }
            })

            return false;
        });

    });
</script>
</body>
</html>